/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.ad.feedsreader.actions;

import com.opensymphony.xwork2.ActionSupport;
import java.util.Map;
import org.apache.struts2.interceptor.SessionAware;
import twitter4j.Twitter;
import twitter4j.TwitterFactory;
import twitter4j.auth.RequestToken;

/**
 *
 * @author sexta13
 */
public class TwitterOAuthRequestAction extends ActionSupport implements SessionAware {

    /**
     * 
     */
    private static final long serialVersionUID = 3568532202451594660L;
    private final static String CONSUMER_KEY = "lZLuzCeR4q86Of6mo6uXQ";
    private final static String CONSUMER_KEY_SECRET = "UbHYn3zmeIDD5tEJYnwgaBEWPEdxAfVggGvwyj6z4Q";
    private final static String REDIRECT_URL ="http://192.168.160.2:8080/feedsreader/jsp/app/acceptTwitter.jsp";
    // private TwitterFactory factory;	
    private Map<String, Object> session;
    private String redirect;

    @Override
    public String execute() throws Exception {

        Twitter twitter = new TwitterFactory().getInstance();
        twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_KEY_SECRET);
        RequestToken requestToken = twitter.getOAuthRequestToken(REDIRECT_URL);
        setRedirect(requestToken.getAuthorizationURL());
        getSession().put("TWITTER", twitter);


        return SUCCESS;

    }

    @Override
    public void setSession(Map<String, Object> session) {
        this.session = session;
    }

    public Map<String, Object> getSession() {
        return session;
    }

    public String getRedirect() {
        return redirect;
    }

    public void setRedirect(String redirect) {
        this.redirect = redirect;
    }
}
